package m.jclecai.com.adapter.KSPagerAdapters;

import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import m.jclecai.com.R;
import m.jclecai.com.inter.IAdapterItemSelect;

/**
 * Created by hp on 2017/4/28.
 * <p>
 * 和值
 */

public class BetSumValueAdapter extends BaseAdapter implements View.OnClickListener {

    private final Context context;
    private final IAdapterItemSelect iAdapterItemSelect;
    private String[] sumValue;
    private String[] sumBonus;
    private int selectMode; //快速选择模式 0首次点击 1大 2小 3单 4双 5大单 6大双 7小单 8小双
    private boolean isInterdict; //是否清除所有选中
    private List<String> betParamete = new LinkedList<>(); //用户投注参数 快速选择
    Map<Integer, Boolean> selectMap = new HashMap<>(); //自选

    public boolean isShowMissData = false;


    //  List<View> mItemViewList = new ArrayList<>();

    // Map<Integer,View> mViewMap=new HashMap<>();

    private boolean isClear;

    //随机数
    private int randomNumber;
    private ListView mListView;
    private String[] mMissData = new String[]{};

    public void clearSelect() {
        isClear = true;
    }

    public BetSumValueAdapter(Context context, IAdapterItemSelect iAdapterItemSelect) {
        this.context = context;
        this.iAdapterItemSelect = iAdapterItemSelect;
    }

    public void setData(String[] sumValue, String[] sumBonus) {
        this.sumValue = sumValue;
        this.sumBonus = sumBonus;
    }

    //获取投注参数
    public List<String> getBetParamete() {
        for (Map.Entry<Integer, Boolean> entry : selectMap.entrySet()) {
            if (entry.getValue()) {
                betParamete.add(entry.getKey() + "");
            }
        }
        return betParamete;
    }

    public void setListView(ListView listView) {
        mListView = listView;
    }

    public void setRandomNumber(int randomNumber) {
      /*  isClear = true;
        this.randomNumber = randomNumber;*/
        //这里我我们是需要根据randomNumber来选中相应的数字；
        clearAll();
        List<String> stringList = Arrays.asList(sumValue);
        int numPosition = stringList.indexOf(randomNumber + "");
        int holderPostion = numPosition / 4;
        int itemPostion = numPosition % 4;

        View view = mListView.getChildAt(holderPostion);
        ViewHolder viewHolder = (ViewHolder) view.getTag();
        switch (itemPostion) {
            case 0:
                setSelected(viewHolder, viewHolder.tv_number_one, viewHolder.rl_one);
                break;
            case 1:
                setSelected(viewHolder, viewHolder.tv_number_two, viewHolder.rl_two);
                break;
            case 2:
                setSelected(viewHolder, viewHolder.tv_number_three, viewHolder.rl_three);
                break;
            case 3:
                setSelected(viewHolder, viewHolder.tv_number_four, viewHolder.rl_four);
                break;
        }
    }


    @Override
    public int getCount() {
        return sumValue.length / 4 + 1;
    }

    @Override
    public Object getItem(int position) {
        return sumValue[position];
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        int numberOne = 0;
        int numberTwo = 0;
        int numberThree = 0;
        int numberFour = 0;

        ViewHolder holder = null;
        //这里我们不对itemView进行一个复用；
        if (true) {
            holder = new ViewHolder();
            holder.position = position;
            if (position == sumValue.length / 4) {
                convertView = View.inflate(context, R.layout.ks_item_sum_value_bottom, null);
                holder.tv_select_one = (TextView) convertView.findViewById(R.id.tv_select_one);
                holder.tv_select_one.setOnClickListener(this);
                holder.tv_select_two = (TextView) convertView.findViewById(R.id.tv_select_two);
                holder.tv_select_two.setOnClickListener(this);
                holder.tv_select_three = (TextView) convertView.findViewById(R.id.tv_select_three);
                holder.tv_select_three.setOnClickListener(this);
                holder.tv_select_four = (TextView) convertView.findViewById(R.id.tv_select_four);
                holder.tv_select_four.setOnClickListener(this);
                holder.tv_select_one.setTag(holder);
                holder.tv_select_two.setTag(holder);
                holder.tv_select_three.setTag(holder);
                holder.tv_select_four.setTag(holder);
            } else {
                convertView = View.inflate(context, R.layout.ks_item_sum_value, null);
                holder.rl_one = (RelativeLayout) convertView.findViewById(R.id.rl_one);
                holder.rl_one.setOnClickListener(this);
                holder.rl_two = (RelativeLayout) convertView.findViewById(R.id.rl_two);
                holder.rl_two.setOnClickListener(this);
                holder.rl_three = (RelativeLayout) convertView.findViewById(R.id.rl_three);
                holder.rl_three.setOnClickListener(this);
                holder.rl_four = (RelativeLayout) convertView.findViewById(R.id.rl_four);
                holder.rl_four.setOnClickListener(this);

                holder.rl_one.setTag(holder);
                holder.rl_two.setTag(holder);
                holder.rl_three.setTag(holder);
                holder.rl_four.setTag(holder);

                holder.tv_number_one = (TextView) convertView.findViewById(R.id.tv_number_one);
                holder.tv_number_two = (TextView) convertView.findViewById(R.id.tv_number_two);
                holder.tv_number_three = (TextView) convertView.findViewById(R.id.tv_number_three);
                holder.tv_number_four = (TextView) convertView.findViewById(R.id.tv_number_four);

                holder.tv_bonus_one = (TextView) convertView.findViewById(R.id.tv_bonus_one);
                holder.tv_bonus_two = (TextView) convertView.findViewById(R.id.tv_bonus_two);
                holder.tv_bonus_three = (TextView) convertView.findViewById(R.id.tv_bonus_three);
                holder.tv_bonus_four = (TextView) convertView.findViewById(R.id.tv_bonus_four);

                holder.tv_miss_data_one = ((TextView) convertView.findViewById(R.id.tv_miss_data_one));
                holder.tv_miss_data_two = ((TextView) convertView.findViewById(R.id.tv_miss_data_two));
                holder.tv_miss_data_three = ((TextView) convertView.findViewById(R.id.tv_miss_data_three));
                holder.tv_miss_data_four = ((TextView) convertView.findViewById(R.id.tv_miss_data_four));

            }
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        //设置数据
        switch (position) {
            case 0:
                holder.tv_number_one.setText(sumValue[0]);
                holder.tv_number_two.setText(sumValue[1]);
                holder.tv_number_three.setText(sumValue[2]);
                holder.tv_number_four.setText(sumValue[3]);

                holder.tv_bonus_one.setText(sumBonus[0]);
                holder.tv_bonus_two.setText(sumBonus[1]);
                holder.tv_bonus_three.setText(sumBonus[2]);
                holder.tv_bonus_four.setText(sumBonus[3]);

                if (mMissData.length >= 4) {
                    holder.tv_miss_data_one.setText(mMissData[0]);
                    holder.tv_miss_data_two.setText(mMissData[1]);
                    holder.tv_miss_data_three.setText(mMissData[2]);
                    holder.tv_miss_data_four.setText(mMissData[3]);
                } else {
                    holder.tv_miss_data_one.setText("--");
                    holder.tv_miss_data_two.setText("--");
                    holder.tv_miss_data_three.setText("--");
                    holder.tv_miss_data_four.setText("--");
                }

                break;
            case 1:
                holder.tv_number_one.setText(sumValue[4]);
                holder.tv_number_two.setText(sumValue[5]);
                holder.tv_number_three.setText(sumValue[6]);
                holder.tv_number_four.setText(sumValue[7]);
                holder.tv_bonus_one.setText(sumBonus[4]);
                holder.tv_bonus_two.setText(sumBonus[5]);
                holder.tv_bonus_three.setText(sumBonus[6]);
                holder.tv_bonus_four.setText(sumBonus[7]);

                if (mMissData.length >= 7) {
                    holder.tv_miss_data_one.setText(mMissData[4]);
                    holder.tv_miss_data_two.setText(mMissData[5]);
                    holder.tv_miss_data_three.setText(mMissData[6]);
                    holder.tv_miss_data_four.setText(mMissData[7]);
                } else {
                    holder.tv_miss_data_one.setText("--");
                    holder.tv_miss_data_two.setText("--");
                    holder.tv_miss_data_three.setText("--");
                    holder.tv_miss_data_four.setText("--");
                }

                break;
            case 2:
                holder.tv_number_one.setText(sumValue[8]);
                holder.tv_number_two.setText(sumValue[9]);
                holder.tv_number_three.setText(sumValue[10]);
                holder.tv_number_four.setText(sumValue[11]);
                holder.tv_bonus_one.setText(sumBonus[8]);
                holder.tv_bonus_two.setText(sumBonus[9]);
                holder.tv_bonus_three.setText(sumBonus[10]);
                holder.tv_bonus_four.setText(sumBonus[11]);

                if (mMissData.length >= 12) {
                    holder.tv_miss_data_one.setText(mMissData[8]);
                    holder.tv_miss_data_two.setText(mMissData[9]);
                    holder.tv_miss_data_three.setText(mMissData[10]);
                    holder.tv_miss_data_four.setText(mMissData[11]);
                } else {
                    holder.tv_miss_data_one.setText("--");
                    holder.tv_miss_data_two.setText("--");
                    holder.tv_miss_data_three.setText("--");
                    holder.tv_miss_data_four.setText("--");
                }

                break;
            case 3:
                holder.tv_number_one.setText(sumValue[12]);
                holder.tv_number_two.setText(sumValue[13]);
                holder.tv_number_three.setText(sumValue[14]);
                holder.tv_number_four.setText(sumValue[15]);
                holder.tv_bonus_one.setText(sumBonus[12]);
                holder.tv_bonus_two.setText(sumBonus[13]);
                holder.tv_bonus_three.setText(sumBonus[14]);
                holder.tv_bonus_four.setText(sumBonus[15]);


                if (mMissData.length >= 16) {
                    holder.tv_miss_data_one.setText(mMissData[12]);
                    holder.tv_miss_data_two.setText(mMissData[13]);
                    holder.tv_miss_data_three.setText(mMissData[14]);
                    holder.tv_miss_data_four.setText(mMissData[15]);
                } else {
                    holder.tv_miss_data_one.setText("--");
                    holder.tv_miss_data_two.setText("--");
                    holder.tv_miss_data_three.setText("--");
                    holder.tv_miss_data_four.setText("--");
                }
                break;
        }
        if (position < getCount() - 1) {
            //最后一个是没有遗漏的
            if (isShowMissData()) {
                //这里我们让其显示遗漏
                holder.tv_miss_data_one.setVisibility(View.VISIBLE);
                holder.tv_miss_data_two.setVisibility(View.VISIBLE);
                holder.tv_miss_data_three.setVisibility(View.VISIBLE);
                holder.tv_miss_data_four.setVisibility(View.VISIBLE);
            } else {
                //隐藏遗漏
                holder.tv_miss_data_one.setVisibility(View.INVISIBLE);
                holder.tv_miss_data_two.setVisibility(View.INVISIBLE);
                holder.tv_miss_data_three.setVisibility(View.INVISIBLE);
                holder.tv_miss_data_four.setVisibility(View.INVISIBLE);
            }
        }

        if (isClear) {
            clearSelect(holder);
        }

        //大小单双快速选择
        if (position < sumValue.length / 4 && isInterdict) {
            if (position == 0) {
                selectMap.clear();
            }

            holder.rl_one.setBackgroundResource(R.drawable.shape_box_ks_up);
            holder.rl_two.setBackgroundResource(R.drawable.shape_box_ks_up);
            holder.rl_three.setBackgroundResource(R.drawable.shape_box_ks_up);
            holder.rl_four.setBackgroundResource(R.drawable.shape_box_ks_up);

            numberOne = Integer.parseInt(holder.tv_number_one.getText().toString());
            numberTwo = Integer.parseInt(holder.tv_number_two.getText().toString());
            numberThree = Integer.parseInt(holder.tv_number_three.getText().toString());
            numberFour = Integer.parseInt(holder.tv_number_four.getText().toString());
            //逐条清空再逐条添加
            switch (selectMode) {
                case 1://大
                    if (numberOne > 10) {
                        speedinessSelected(holder, holder.tv_number_one, holder.rl_one);
                    }
                    if (numberTwo > 10) {
                        speedinessSelected(holder, holder.tv_number_two, holder.rl_two);
                    }
                    if (numberThree > 10) {
                        speedinessSelected(holder, holder.tv_number_three, holder.rl_three);
                    }
                    if (numberFour > 10) {
                        speedinessSelected(holder, holder.tv_number_four, holder.rl_four);
                    }
                    break;
                case 2: //小
                    if (numberOne <= 10) {
                        speedinessSelected(holder, holder.tv_number_one, holder.rl_one);
                    }
                    if (numberTwo <= 10) {
                        speedinessSelected(holder, holder.tv_number_two, holder.rl_two);
                    }
                    if (numberThree <= 10) {
                        speedinessSelected(holder, holder.tv_number_three, holder.rl_three);
                    }
                    if (numberFour <= 10) {
                        speedinessSelected(holder, holder.tv_number_four, holder.rl_four);
                    }
                    break;
                case 3: //单
                    speedinessSelected(holder, holder.tv_number_one, holder.rl_one);
                    speedinessSelected(holder, holder.tv_number_three, holder.rl_three);
                    break;
                case 4: //双
                    speedinessSelected(holder, holder.tv_number_two, holder.rl_two);
                    speedinessSelected(holder, holder.tv_number_four, holder.rl_four);
                    break;
                case 5: //大单
                    if (numberOne > 10) {
                        speedinessSelected(holder, holder.tv_number_one, holder.rl_one);
                    }
                    if (numberThree > 10) {
                        speedinessSelected(holder, holder.tv_number_three, holder.rl_three);
                    }
                    break;
                case 6: //大双
                    if (numberTwo > 10) {
                        speedinessSelected(holder, holder.tv_number_two, holder.rl_two);
                    }
                    if (numberFour > 10) {
                        speedinessSelected(holder, holder.tv_number_four, holder.rl_four);
                    }
                    break;
                case 7: //小单
                    if (numberOne < 10) {
                        speedinessSelected(holder, holder.tv_number_one, holder.rl_one);
                    }
                    if (numberThree < 10) {
                        speedinessSelected(holder, holder.tv_number_three, holder.rl_three);
                    }
                    break;
                case 8: //小双
                    if (numberTwo <= 10) {
                        speedinessSelected(holder, holder.tv_number_two, holder.rl_two);
                    }
                    if (numberFour <= 10) {
                        speedinessSelected(holder, holder.tv_number_four, holder.rl_four);
                    }
                    break;
            }
        } else if (position == sumValue.length / 4 && isInterdict) {
            clearSelect(holder.tv_select_one);
            clearSelect(holder.tv_select_two);
            clearSelect(holder.tv_select_three);
            clearSelect(holder.tv_select_four);
            isInterdict = false;
            iAdapterItemSelect.adapterItemSelect(selectMap);
            Log.i("一一一一一一一一一一", "1");
            switch (selectMode) {
                case 1:
                    selectMode(holder.tv_select_one);
                    break;
                case 2:
                    selectMode(holder.tv_select_two);
                    break;
                case 3:
                    selectMode(holder.tv_select_three);
                    break;
                case 4:
                    selectMode(holder.tv_select_four);
                    break;
                case 5:
                    selectMode(holder.tv_select_one);
                    selectMode(holder.tv_select_three);
                    break;
                case 6:
                    selectMode(holder.tv_select_one);
                    selectMode(holder.tv_select_four);
                    break;
                case 7:
                    selectMode(holder.tv_select_two);
                    selectMode(holder.tv_select_three);
                    break;
                case 8:
                    selectMode(holder.tv_select_two);
                    selectMode(holder.tv_select_four);
                    break;
            }
        }

        //随机
        if (randomNumber != 0 && position < sumValue.length / 4) {

            if (randomNumber == Integer.parseInt(holder.tv_number_one.getText().toString())) {
                speedinessSelected(holder, holder.tv_number_one, holder.rl_one);
            } else if (randomNumber == Integer.parseInt(holder.tv_number_two.getText().toString())) {
                speedinessSelected(holder, holder.tv_number_two, holder.rl_two);
            } else if (randomNumber == Integer.parseInt(holder.tv_number_three.getText().toString())) {
                speedinessSelected(holder, holder.tv_number_three, holder.rl_three);
            } else if (randomNumber == Integer.parseInt(holder.tv_number_four.getText().toString())) {
                speedinessSelected(holder, holder.tv_number_four, holder.rl_four);
            }

            if (position == sumValue.length / 4 - 1) {
                randomNumber = 0;
                isClear = false;
            }
        }


        return convertView;
    }


    //普通选号
    int key; //键名

    private void setSelected(ViewHolder holder, TextView tv, RelativeLayout rl) {
        Log.i("一一一一一一一一一一一", "随机数=" + randomNumber);
        key = 0;
        isInterdict = false;
        key = Integer.parseInt(tv.getText().toString());
        //选中过设置未选中
        if (holder.isSelected(key)) {
            Log.i("一一一一一一一一一一一", "选中");
            rl.setBackgroundResource(R.drawable.shape_box_ks_up);
            tv.setTextColor(tv.getContext().getResources().getColor(R.color.white));
            //这里我们要设置，数字下方的字符串的颜色，我们只能这样：
            if (holder.rl_one == rl) {
                holder.tv_bonus_one.setTextColor(tv.getContext().getResources().getColor(R.color.white));
            } else if (holder.rl_two == rl) {
                holder.tv_bonus_two.setTextColor(tv.getContext().getResources().getColor(R.color.white));
            } else if (holder.rl_three == rl) {
                holder.tv_bonus_three.setTextColor(tv.getContext().getResources().getColor(R.color.white));
            } else if (holder.rl_four == rl) {
                holder.tv_bonus_four.setTextColor(tv.getContext().getResources().getColor(R.color.white));
            }
            holder.removeSelected(key);
        } else {
            Log.i("一一一一一一一一一一一", "未选中");
            rl.setBackgroundResource(R.drawable.shape_box_ks_down);
            tv.setTextColor(tv.getContext().getResources().getColor(R.color.yello));

            if (holder.rl_one == rl) {
                holder.tv_bonus_one.setTextColor(tv.getContext().getResources().getColor(R.color.yello));
            } else if (holder.rl_two == rl) {
                holder.tv_bonus_two.setTextColor(tv.getContext().getResources().getColor(R.color.yello));
            } else if (holder.rl_three == rl) {
                holder.tv_bonus_three.setTextColor(tv.getContext().getResources().getColor(R.color.yello));
            } else if (holder.rl_four == rl) {
                holder.tv_bonus_four.setTextColor(tv.getContext().getResources().getColor(R.color.yello));
            }
            holder.setSelected(key, true);
        }
    }

    //快速选号
    private void speedinessSelected(ViewHolder holder, TextView tv, RelativeLayout rl) {
        key = 0;
        key = Integer.parseInt(tv.getText().toString());
        rl.setBackgroundResource(R.drawable.shape_box_ks_down);
        tv.setTextColor(tv.getResources().getColor(R.color.yello));

        if (holder.rl_one == rl) {
            holder.tv_bonus_one.setTextColor(tv.getContext().getResources().getColor(R.color.yello));
        } else if (holder.rl_two == rl) {
            holder.tv_bonus_two.setTextColor(tv.getContext().getResources().getColor(R.color.yello));
        } else if (holder.rl_three == rl) {
            holder.tv_bonus_three.setTextColor(tv.getContext().getResources().getColor(R.color.yello));
        } else if (holder.rl_four == rl) {
            holder.tv_bonus_four.setTextColor(tv.getContext().getResources().getColor(R.color.yello));
        }

        holder.setSelected(key, true);
    }

    private void clearSelect(ViewHolder holder) {
        if (holder.position == 0) {
            //这里表示只有第一次会对其进行一个清理
            selectMap.clear();
            betParamete.clear();
        }
        if (holder.position < sumValue.length / 4) {
            holder.rl_one.setBackgroundResource(R.drawable.shape_box_ks_up);
            holder.rl_two.setBackgroundResource(R.drawable.shape_box_ks_up);
            holder.rl_three.setBackgroundResource(R.drawable.shape_box_ks_up);
            holder.rl_four.setBackgroundResource(R.drawable.shape_box_ks_up);

            holder.tv_bonus_one.setTextColor(holder.rl_four.getResources().getColor(R.color.white));
            holder.tv_bonus_two.setTextColor(holder.rl_four.getResources().getColor(R.color.white));
            holder.tv_bonus_three.setTextColor(holder.rl_four.getResources().getColor(R.color.white));
            holder.tv_bonus_four.setTextColor(holder.rl_four.getResources().getColor(R.color.white));

            holder.tv_number_one.setTextColor(holder.rl_four.getResources().getColor(R.color.white));
            holder.tv_number_two.setTextColor(holder.rl_four.getResources().getColor(R.color.white));
            holder.tv_number_three.setTextColor(holder.rl_four.getResources().getColor(R.color.white));
            holder.tv_number_four.setTextColor(holder.rl_four.getResources().getColor(R.color.white));
        } else {
            clearSelect(holder.tv_select_one);
            clearSelect(holder.tv_select_two);
            clearSelect(holder.tv_select_three);
            clearSelect(holder.tv_select_four);
        }
    }

    boolean isQuickSelected = false;

    @Override
    public void onClick(View v) {

        ViewHolder holder = (ViewHolder) v.getTag();
        switch (v.getId()) {
            case R.id.rl_one:
                setSelected(holder, holder.tv_number_one, holder.rl_one);
                isQuickSelected = false;
                break;
            case R.id.rl_two:
                setSelected(holder, holder.tv_number_two, holder.rl_two);
                isQuickSelected = false;
                break;
            case R.id.rl_three:
                setSelected(holder, holder.tv_number_three, holder.rl_three);
                isQuickSelected = false;
                break;
            case R.id.rl_four:
                setSelected(holder, holder.tv_number_four, holder.rl_four);
                isQuickSelected = false;
                break;
            case R.id.tv_select_one: //大
                isInterdict = true;
                isQuickSelected = true;
                switch (selectMode) {
                    case 0:
                        selectMode = 1;
                        break;
                    case 1:
                        selectMode = 0;
                        break;
                    case 2:
                        selectMode = 1;
                        break;
                    case 3:
                        selectMode = 5;
                        break;
                    case 4:
                        selectMode = 6;
                        break;
                    case 5:
                        selectMode = 3;
                        break;
                    case 6:
                        selectMode = 4;
                        break;
                    case 7:
                        selectMode = 5;
                        break;
                    case 8:
                        selectMode = 6;
                        break;
                }
                break;
            case R.id.tv_select_two: //小
                isInterdict = true;
                isQuickSelected = true;
                switch (selectMode) {
                    case 0:
                        selectMode = 2;
                        break;
                    case 1:
                        selectMode = 2;
                        break;
                    case 2:
                        selectMode = 0;
                        break;
                    case 3:
                        selectMode = 7;
                        break;
                    case 4:
                        selectMode = 8;
                        break;
                    case 5:
                        selectMode = 7;
                        break;
                    case 6:
                        selectMode = 8;
                        break;
                    case 7:
                        selectMode = 3;
                        break;
                    case 8:
                        selectMode = 4;
                        break;
                }
                break;
            case R.id.tv_select_three://单
                isInterdict = true;
                isQuickSelected = true;
                switch (selectMode) {
                    case 0:
                        selectMode = 3;
                        break;
                    case 1:
                        selectMode = 5;
                        break;
                    case 2:
                        selectMode = 7;
                        break;
                    case 3:
                        selectMode = 0;
                        break;
                    case 4:
                        selectMode = 3;
                        break;
                    case 5:
                        selectMode = 1;
                        break;
                    case 6:
                        selectMode = 5;
                        break;
                    case 7:
                        selectMode = 2;
                        break;
                    case 8:
                        selectMode = 7;
                        break;
                }
                break;
            case R.id.tv_select_four: //双
                isInterdict = true;
                isQuickSelected = true;
                switch (selectMode) {
                    case 0:
                        selectMode = 4;
                        break;
                    case 1:
                        selectMode = 6;
                        break;
                    case 2:
                        selectMode = 8;
                        break;
                    case 3:
                        selectMode = 4;
                        break;
                    case 4:
                        selectMode = 0;
                        break;
                    case 5:
                        selectMode = 6;
                        break;
                    case 6:
                        selectMode = 1;
                        break;
                    case 7:
                        selectMode = 8;
                        break;
                    case 8:
                        selectMode = 2;
                        break;
                }
                break;

        }
        // notifyDataSetChanged();
        if (isQuickSelected) {
            //这里实现快速选号的局部刷新；
            notifyDataOnSelectMode();
        }
    }

    /**
     * 根据选中的模式实现局部刷新；
     */
    private void notifyDataOnSelectMode() {
        ViewHolder holder0 = (ViewHolder) mListView.getChildAt(0).getTag();
        ViewHolder holder1 = (ViewHolder) mListView.getChildAt(1).getTag();
        ViewHolder holder2 = (ViewHolder) mListView.getChildAt(2).getTag();
        ViewHolder holder3 = (ViewHolder) mListView.getChildAt(3).getTag();
        ViewHolder holder4 = (ViewHolder) mListView.getChildAt(4).getTag();
        //1、清空所有
        clearAll();
        //2、设置相应的条目；
        switch (selectMode) {
            case 0:
                break;
            case 1: //大
                //选中相应的条目，然后，将其添加到Map中；

                setSelected(holder2, holder2.tv_number_one, holder2.rl_one);
                setSelected(holder2, holder2.tv_number_three, holder2.rl_three);

                setSelected(holder2, holder2.tv_number_four, holder2.rl_four);
                setSelected(holder2, holder2.tv_number_two, holder2.rl_two);


                setSelected(holder3, holder3.tv_number_one, holder3.rl_one);
                setSelected(holder3, holder3.tv_number_three, holder3.rl_three);

                setSelected(holder3, holder3.tv_number_two, holder3.rl_two);
                setSelected(holder3, holder3.tv_number_four, holder3.rl_four);

                selectMode(holder4.tv_select_one);
                break;
            case 2://小

                setSelected(holder0, holder0.tv_number_one, holder0.rl_one);
                setSelected(holder0, holder0.tv_number_two, holder0.rl_two);
                setSelected(holder0, holder0.tv_number_three, holder0.rl_three);
                setSelected(holder0, holder0.tv_number_four, holder0.rl_four);

                setSelected(holder1, holder1.tv_number_one, holder1.rl_one);
                setSelected(holder1, holder1.tv_number_two, holder1.rl_two);
                setSelected(holder1, holder1.tv_number_three, holder1.rl_three);
                setSelected(holder1, holder1.tv_number_four, holder1.rl_four);

                //setSelected(holder4, holder4.tv_number_two, holder4.rl_four);
                selectMode(holder4.tv_select_two);
                break;
            case 3: //单
                setSelected(holder0, holder0.tv_number_one, holder0.rl_one);
                setSelected(holder0, holder0.tv_number_three, holder0.rl_three);

                setSelected(holder1, holder1.tv_number_one, holder1.rl_one);
                setSelected(holder1, holder1.tv_number_three, holder1.rl_three);

                setSelected(holder2, holder2.tv_number_one, holder2.rl_one);
                setSelected(holder2, holder2.tv_number_three, holder2.rl_three);

                setSelected(holder3, holder3.tv_number_one, holder3.rl_one);
                setSelected(holder3, holder3.tv_number_three, holder3.rl_three);

                // setSelected(holder4, holder4.tv_number_three, holder4.rl_three);
                selectMode(holder4.tv_select_three);
                break;
            case 4: //双

                setSelected(holder0, holder0.tv_number_two, holder0.rl_two);
                setSelected(holder0, holder0.tv_number_four, holder0.rl_four);

                setSelected(holder1, holder1.tv_number_two, holder1.rl_two);
                setSelected(holder1, holder1.tv_number_four, holder1.rl_four);

                setSelected(holder2, holder2.tv_number_two, holder2.rl_two);
                setSelected(holder2, holder2.tv_number_four, holder2.rl_four);

                setSelected(holder3, holder3.tv_number_two, holder3.rl_two);
                setSelected(holder3, holder3.tv_number_four, holder3.rl_four);

                //  setSelected(holder4, holder4.tv_number_four, holder4.rl_three);
                selectMode(holder4.tv_select_four);
                break;
            case 5: //大单
                setSelected(holder2, holder2.tv_number_one, holder2.rl_one);
                setSelected(holder2, holder2.tv_number_three, holder2.rl_three);

                setSelected(holder3, holder3.tv_number_one, holder3.rl_one);
                setSelected(holder3, holder3.tv_number_three, holder3.rl_three);


                selectMode(holder4.tv_select_one);
                selectMode(holder4.tv_select_three);


                break;
            case 6:  //大双

                setSelected(holder2, holder2.tv_number_two, holder2.rl_two);
                setSelected(holder2, holder2.tv_number_four, holder2.rl_four);

                setSelected(holder3, holder3.tv_number_two, holder3.rl_two);
                setSelected(holder3, holder3.tv_number_four, holder3.rl_four);

                selectMode(holder4.tv_select_one);
                selectMode(holder4.tv_select_four);

                break;
            case 7: //小单

                setSelected(holder0, holder0.tv_number_one, holder0.rl_one);
                setSelected(holder0, holder0.tv_number_three, holder0.rl_three);

                setSelected(holder1, holder1.tv_number_one, holder1.rl_one);
                setSelected(holder1, holder1.tv_number_three, holder1.rl_three);

                selectMode(holder4.tv_select_two);
                selectMode(holder4.tv_select_three);
                break;
            case 8://小双
                setSelected(holder0, holder0.tv_number_two, holder0.rl_two);
                setSelected(holder0, holder0.tv_number_four, holder0.rl_four);

                setSelected(holder1, holder1.tv_number_two, holder1.rl_two);
                setSelected(holder1, holder1.tv_number_four, holder1.rl_four);

                selectMode(holder4.tv_select_two);
                selectMode(holder4.tv_select_four);
                break;
        }
    }

    public void clearAll() {

        for (int i = 0; i < mListView.getChildCount(); i++) {
            View view = mListView.getChildAt(i);
            ViewHolder holder = (ViewHolder) view.getTag();
            clearSelect(holder);
        }
        isClear = false;
        iAdapterItemSelect.adapterItemSelect(selectMap);
    }

    //设置选中
    private void selectMode(TextView tv) {
        tv.setBackgroundResource(R.color.yello);
        tv.setTextColor(Color.parseColor("#139051"));
    }

    //清除选中
    private void clearSelect(TextView tv) {
        tv.setBackgroundResource(R.color.green_1);
        tv.setTextColor(Color.parseColor("#FFFFFF"));
    }


    public class ViewHolder {
        RelativeLayout rl_one;
        RelativeLayout rl_two;
        RelativeLayout rl_three;
        RelativeLayout rl_four;

        int position;


        TextView tv_number_one;
        TextView tv_number_two;
        TextView tv_number_three;
        TextView tv_number_four;

        TextView tv_bonus_one;
        TextView tv_bonus_two;
        TextView tv_bonus_three;
        TextView tv_bonus_four;

        TextView tv_miss_data_one;
        TextView tv_miss_data_two;
        TextView tv_miss_data_three;
        TextView tv_miss_data_four;

        TextView tv_select_one;
        TextView tv_select_two;
        TextView tv_select_three;
        TextView tv_select_four;


        public void setSelected(int key, boolean value) {
            selectMap.put(key, value);
            iAdapterItemSelect.adapterItemSelect(selectMap);
            Log.i("一一一一一一一一一一", "3");
        }

        public void removeSelected(int key) {
            selectMap.remove(key);
            iAdapterItemSelect.adapterItemSelect(selectMap);
            Log.i("一一一一一一一一一一", "4");
        }

        public boolean isSelected(int key) {
            if (selectMap.get(key) == null) {
                return false;
            } else {
                return selectMap.get(key);
            }
        }
    }


    public boolean isShowMissData() {
        return isShowMissData;
    }

    public void showMissData() {
        //这里我们将显示遗漏
        isShowMissData = true;

        if (mListView.getChildCount() == 0) {
            notifyDataSetChanged();

        } else {
            ViewHolder holder0 = (ViewHolder) mListView.getChildAt(0).getTag();
            ViewHolder holder1 = (ViewHolder) mListView.getChildAt(1).getTag();
            ViewHolder holder2 = (ViewHolder) mListView.getChildAt(2).getTag();
            ViewHolder holder3 = (ViewHolder) mListView.getChildAt(3).getTag();

            holder0.tv_miss_data_one.setVisibility(View.VISIBLE);
            holder0.tv_miss_data_two.setVisibility(View.VISIBLE);
            holder0.tv_miss_data_three.setVisibility(View.VISIBLE);
            holder0.tv_miss_data_four.setVisibility(View.VISIBLE);

            holder1.tv_miss_data_one.setVisibility(View.VISIBLE);
            holder1.tv_miss_data_two.setVisibility(View.VISIBLE);
            holder1.tv_miss_data_three.setVisibility(View.VISIBLE);
            holder1.tv_miss_data_four.setVisibility(View.VISIBLE);

            holder2.tv_miss_data_one.setVisibility(View.VISIBLE);
            holder2.tv_miss_data_two.setVisibility(View.VISIBLE);
            holder2.tv_miss_data_three.setVisibility(View.VISIBLE);
            holder2.tv_miss_data_four.setVisibility(View.VISIBLE);

            holder3.tv_miss_data_one.setVisibility(View.VISIBLE);
            holder3.tv_miss_data_two.setVisibility(View.VISIBLE);
            holder3.tv_miss_data_three.setVisibility(View.VISIBLE);
            holder3.tv_miss_data_four.setVisibility(View.VISIBLE);

        }
    }

    public void hideMissData() {
        //这里我们将隐藏遗漏
        isShowMissData = false;

        int childCount = mListView.getChildCount();
        if (childCount == 0) {
            notifyDataSetChanged();
        } else {


            ViewHolder holder0 = (ViewHolder) mListView.getChildAt(0).getTag();
            ViewHolder holder1 = (ViewHolder) mListView.getChildAt(1).getTag();
            ViewHolder holder2 = (ViewHolder) mListView.getChildAt(2).getTag();
            ViewHolder holder3 = (ViewHolder) mListView.getChildAt(3).getTag();

            holder0.tv_miss_data_one.setVisibility(View.INVISIBLE);
            holder0.tv_miss_data_two.setVisibility(View.INVISIBLE);
            holder0.tv_miss_data_three.setVisibility(View.INVISIBLE);
            holder0.tv_miss_data_four.setVisibility(View.INVISIBLE);

            holder1.tv_miss_data_one.setVisibility(View.INVISIBLE);
            holder1.tv_miss_data_two.setVisibility(View.INVISIBLE);
            holder1.tv_miss_data_three.setVisibility(View.INVISIBLE);
            holder1.tv_miss_data_four.setVisibility(View.INVISIBLE);

            holder2.tv_miss_data_one.setVisibility(View.INVISIBLE);
            holder2.tv_miss_data_two.setVisibility(View.INVISIBLE);
            holder2.tv_miss_data_three.setVisibility(View.INVISIBLE);
            holder2.tv_miss_data_four.setVisibility(View.INVISIBLE);

            holder3.tv_miss_data_one.setVisibility(View.INVISIBLE);
            holder3.tv_miss_data_two.setVisibility(View.INVISIBLE);
            holder3.tv_miss_data_three.setVisibility(View.INVISIBLE);
            holder3.tv_miss_data_four.setVisibility(View.INVISIBLE);

        }


    }

    public void addMissDataInfo(String missData) {
        mMissData = missData.split(",");


        if (mListView.getChildCount() == 0) {
            notifyDataSetChanged();
        } else {
            if (mMissData.length >= 16) {
                for (int i = 0; i < mListView.getChildCount() - 1; i++) {
                    ViewHolder viewHolder = (ViewHolder) mListView.getChildAt(i).getTag();
                    //没一个条目有五个子view;
                    viewHolder.tv_miss_data_one.setText(mMissData[i * 4 + 0]);
                    viewHolder.tv_miss_data_two.setText(mMissData[i * 4 + 1]);
                    viewHolder.tv_miss_data_three.setText(mMissData[i * 4 + 2]);
                    viewHolder.tv_miss_data_four.setText(mMissData[i * 4 + 3]);
                }
            } else {
                for (int i = 0; i < mListView.getChildCount() - 1; i++) {
                    ViewHolder viewHolder = (ViewHolder) mListView.getChildAt(i).getTag();
                    //没一个条目有五个子view;
                    viewHolder.tv_miss_data_one.setText("--");
                    viewHolder.tv_miss_data_two.setText("--");
                    viewHolder.tv_miss_data_three.setText("--");
                    viewHolder.tv_miss_data_four.setText("--");
                }
            }

        }

    }
}
